$(function () {
 
  $(".checkbox-toggle").click(function () {
      var clicks = $(this).data('clicks');
      if (clicks) {
        //Uncheck all checkboxes
        $(".mailbox-messages input[type='checkbox']").iCheck("uncheck");
        $(".fa", this).removeClass("fa-check-square-o").addClass('fa-square-o');
      } else {
        //Check all checkboxes
        $(".mailbox-messages input[type='checkbox']").iCheck("check");
        $(".fa", this).removeClass("fa-square-o").addClass('fa-check-square-o');
      }
      $(this).data("clicks", !clicks);
    });

  $("[name='btn_payment']").click(function () {
	  var payment = new Array();
	  var sumprice = 0;
	  $("input[name='node_checker']").each(function(i){  
	    var isCheck = $(this).prop("checked");
	    var id = $(this).attr("id");
	    if('checked' == isCheck || isCheck){
	    	console.log($("#id"+id).val());
	    	if($("#id"+id).val()=="false"){
	    		$("#"+id).hide();
		    	$("#zf"+id).html('<span class=\"text-green\">已支付</span>');
		    	var json = {};
		    	json.salesman_id = $("#salesman_id"+id).val();
		    	json.company_id = $("#company_id"+id).val();
		    	json.product_id = $("#product_id"+id).val();
		    	json.nubs = $("#nubs"+id).val();
		    	json.price = $("#price"+id).val();
		    	json.sumprice = $("#sumprice"+id).val();
		    	json.openid = $("#openid"+id).val();
		    	json.appid = $("#appid"+id).val();
		    	json.tableid = $("#tableid"+id).val();
 		    	sumprice = Number(sumprice)+Number($("#sumprice"+id).val());
		    	payment.push(json);
	    	}
	    }
	  });
	  if(payment.length<=0){
		  bootbox.balert("请选择需要支付的促销员！");
     	  return false ;
	  }
	  var payments = {List: payment,product_id:$("#product_id").val()};
	  bootbox.bconfirm("请确认是否需要支付"+payment.length+"名促销员共计￥"+sumprice+"！", function (re) {
		  if (re) {
			  $("input[name='node_checker']").each(function(i){  
				    var isCheck = $(this).prop("checked");
				    var id = $(this).attr("id");
				    if('checked' == isCheck || isCheck){
				    	//区别是否重复提交
				    	if($("#id"+id).val()=="false"){
				    		$("#id"+id).val("true");
				    	}
				    }
			  });
			  $.putJsonBody("/payment/paymentsave" , payments, function (re) {
		        	//window.location.href=window.location.href; 
		        	//window.location.reload; 
	          })
		  }else{
			  payment = new Array();
			  $("input[name='node_checker']").each(function(i){  
				    var isCheck = $(this).prop("checked");
				    var id = $(this).attr("id");
				    if('checked' == isCheck || isCheck){
				    	if($("#id"+id).val()=="false"){
				    		$("#"+id).show();
					    	$("#zf"+id).html('<span class=\"text-danger\">未支付</span>');
				    	}
				    }
				  });
		  }
	  });
  });
  
  
});